home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Diamond Collection / The Diamond Collection (Software Vault)(Digital Impact).ISO / cdr27 / doonce23.zip / DO-ONCE.DOC next >
Text File  |  1995-02-16  |  22KB  |  458 lines

  1. NOTE:  This program is offered as a "FREEBIE"
  2.        NO donations are requested or accepted.  I've used enough other
  3.          people's freebies that this is offered as only a partial repayment
  4.          for their time and effort.  My only request is that if you have
  5.          any suggestions, bug reports, or comments (I LOVE comments!),
  6.          please drop me a line or leave a message for me:
  7.  
  8.          CompuServe       72317,2751
  9.          Internet         glenn.snow@sdorm.org
  10.          BBS              (312) 684-9267   (14.4,N81)
  11.  
  12.  
  13. ------------------ PURPOSE AND FUNCTION OF PROGRAM ----------------
  14.  
  15. This program was designed to help take care of some "regular" chores...
  16. ones which I usually performed either once a day (optimizing my disk),
  17. once a week (using TIMESET to call the Naval Observatory Clock and set the
  18. time on my computer), or once a month (using SpinRite to renew the low-level
  19. format of my hard disk) ... no matter how many times during that particular
  20. day I booted my computer.
  21.  
  22. ----------------------------- ENVIRONMENT --------------------------
  23.  
  24. This program was designed to run on an IBM PC/XT/AT or compatible.  It should
  25. also run on the PS/2 without difficulty.  It runs under MS-DOS or PC-DOS
  26. version 2.0 or later.  It is NOT designed to run under OS/2.  In terms of
  27. hardware, it was designed to be run from a hard disk, and although it should
  28. work on a floppy machine, the author neither claims that it will work, nor 
  29. understands why anyone would bother.  Of course, a valid time and date are
  30. expected to be on the system clock...If there is no real-time clock, then
  31. the time and date should be entered BEFORE running DO-ONCE.  Otherwise,
  32. nothing would EVER run a second time, since as far as the machine is 
  33. concerned, it would ALWAYS be January 1, 1980.  (Gee, Dad, is that when
  34. the Universe began?)
  35.  
  36. ------------------------------- SYNTAX -----------------------------
  37.  
  38. The syntax of DO-ONCE is:
  39.  
  40.        DO-ONCE [/q] [@DAY] [d:\path\]FILENAME.EXT [PARAM1 PARAM2 PARAM3 ETC]
  41.  
  42. /Q will set the quiet mode "on."  That means less screen clutter.
  43. Informational messages are not displayed.                
  44.                 
  45. DAY is the name of the day of the week that you want it to occur
  46. on, OR the day of the month.  (i.e.   TUE  or   SAT   or   1   or 15)
  47.  
  48. FILENAME is the program you want to run.
  49.  
  50. You can PATH to the FILENAME, if it isn't in your normal PATH using the 
  51.   optional d:\path\ in front of the FILENAME.  Also note that the EXTension
  52.   is not necessary (unless you want to force DOS to bypass its normal
  53.   execution search priority)
  54.  
  55. Only the first three letters of the @DAY parameter matter, so
  56.    @MON   or   @THU  would work just fine.
  57.    
  58. Versions 2.1 and later offer the possibility of running a program not only
  59.    by the proper weekday, but by the day of the month.  Thus, it can execute
  60.    requested programs ONLY on the 15th of the month, if you want.  You
  61.    would do this by using the @ parameter with a number,   @15   for example.
  62.    
  63. If you run DO-ONCE without any parameters, it will give you a brief
  64. synopsis of the command syntax and parameter possibilities.
  65.  
  66. Version 2.3 offers the possibility of including redirection within the 
  67. requested command line.  If you need this capability, use the following
  68. symbols in your DO-ONCE request:
  69.  
  70. `] will be replaced by the redirection symbol   >
  71. `[ will be replaced by the redirection symbol   <
  72. `^ will be replaced by the piping symbol        |
  73.  
  74.  
  75. Note:  Versions 2.1 and later provide the option of running the program on the 
  76.        first day AFTER it is due to be run, just in case you didn't turn
  77.        on the computer on the EXACT day.  You may activate this option by
  78.        adding the    +   (plus) character immediately after the @ character.
  79.  
  80.        Thus, DO-ONCE @MON VOPT         -- will run VOPT on Mondays ONLY
  81.        but   DO-ONCE @+MON VOPT        -- will run VOPT on Monday OR on the
  82.                                           next day you boot the machine after
  83.                                           that Monday.  (see examples below)
  84.                                           
  85.       If this is confusing, try reading it this way:
  86.       
  87.       The @  sign equals the word  "ON"
  88.       The @+ sign equals the words "ON OR AFTER"
  89.       
  90. Therefore:      
  91.       
  92.       DO-ONCE @SATURDAY BACKUP        reads:  run BACKUP ON Saturday
  93.       
  94.       DO-ONCE @+SATURDAY BACKUP       reads:  run BACKUP ON OR AFTER Saturday.
  95.       
  96.       DO-ONCE @1 BACKUP               reads:  run BACKUP ON the first of the
  97.                                               month
  98.  
  99.       DO-ONCE @+1 BACKUP              reads:  run BACKUP ON OR AFTER the first
  100.                                               of the month                                              
  101.       
  102.       
  103.       This way, with the "ON OR AFTER" option, if you don't happen to turn 
  104.       on the machine on Saturday, it will "remember" that it was SUPPOSED
  105.       to run on Saturday, and when you start up on the following Monday, (for
  106.       instance) it will run it.
  107.  
  108. The @+ operator can be used before either a DAY or a NUMBER:  
  109.                    @+THU  is fine, as is    @+15
  110.                    
  111.                    
  112. NOTE THAT THERE SHOULD BE NO SPACES BETWEEN THE @  (OR @+) AND THE DAY!
  113.  
  114.  
  115.                --------------------------------------
  116. ERRORLEVEL responses:
  117.  
  118.   If you run DO-ONCE and the requested program is RUN, it returns an
  119.   ERRORLEVEL of 0.
  120.  
  121.   If you run DO-ONCE and the requested program is NOT RUN, it returns an
  122.   ERRORLEVEL of 1.
  123.  
  124.   If you run DO-ONCE without any parameters, it gives a synopsis of the
  125.   command syntax, and exits with an ERRORLEVEL of 2.
  126.   
  127.   If you run DO-ONCE and the environment variable is SET to an invalid
  128.   or non-existent directory, it exits with an errorlevel of 3.
  129.   
  130.                    ------------------------------------
  131.  
  132. CAUTIONS:
  133.  
  134. 1)   You should not use DO-ONCE to load TSR's, even from a batch file.  DO-ONCE
  135.   uses a secondary command processor to load and run programs.  If you load
  136.   any resident programs from within DO-ONCE, although they will run just fine,
  137.   you will be wasting a big chunk of your valuable RAM.  This chunk will
  138.   remain unavailable until you either remove the TSR or reboot.  If you
  139.   absolutely need to load a TSR once a day/week/month, do it this way
  140.   instead:
  141.   
  142.   DO-ONCE ECHO Loading FOO-BAR-TSR...
  143.   IF ERRORLEVEL 1 GOTO :CONTINUE
  144.   FOO-BAR-TSR
  145.   :CONTINUE
  146.   
  147.   This will load the FOO-BAR-TSR  (or whatever it's called), not from
  148.   within the DO-ONCE program, but from the regular batch file.  This way
  149.   your memory will not be wasted on excess copies of COMMAND.COM.
  150.   
  151. 2)  Please note (as explained in the "re-direction" section below) that
  152.   you should not use a disk-optimizing program while output is being
  153.   re-directed to a file, or cross-linking of file clusters can occur.
  154.   
  155.  
  156. ----------------------------- EXAMPLES -------------------------------
  157.  
  158. Example:  Every Monday (and ONLY if it's a Monday), when I first start
  159.           my machine, I want it to run the TIMESET program, in AUTO mode.
  160.           But if I reboot my machine, I don't want it to run TIMESET every
  161.           time...just the first time.  So my AUTOEXEC.BAT file has the
  162.           following line:
  163.           
  164.           DO-ONCE @MONDAY TIMESET AUTO
  165.           
  166.           
  167. Example:  Every day, when I first start up my machine, I want it to run
  168.           the VOPT program, optimizing my hard disk on Drive C and again
  169.           on Drive D.  But I don't want to run VOPT every time I hang and
  170.           reboot the computer, so my AUTOEXEC.BAT file contains the
  171.           following lines:
  172.           
  173.           DO-ONCE VOPT C:
  174.           DO-ONCE VOPT D:
  175.  
  176.  
  177. Example:  On the first of each month, I want to run a batch file called
  178.           POSTACCT, which posts my accounting program entries for the last
  179.           month, and starts a new month.  But if the first of the month
  180.           happens to occur on a Sunday, when I don't boot up my machine, I
  181.           would like it to POSTACCT on the following day, or whenever I next
  182.           start up.  Soooooooooo.... I put the following line in my 
  183.           autoexec.bat:
  184.           
  185.           DO-ONCE @+1 POSTACCT
  186.           
  187. Example:  Every day, I want to run CHKDSK on my hard disk, with the /F
  188.           parameter...and to automatically toss out any lost clusters
  189.           it may find...but I don't want to have to answer "No" to CHKDSK's
  190.           question about such lost clusters...sooooooooooo, I put this line in
  191.           my AUTOEXEC.BAT
  192.           
  193.           DO-ONCE ECHO N `^ CHKDSK /F
  194.           
  195.           which DO-ONCE will pass to DOS as the command line:
  196.           ECHO N | CHKDSK /F
  197.           
  198.           
  199.                                ________________
  200.                                STACKING DO-ONCE
  201.                                ----------------          
  202. Example:  I have a Lions Club meeting on the first Friday of each month, and
  203.           I like to have a reminder when I start the machine, so that I don't
  204.           forget about the Club lunch.  Here I can STACK the DO-ONCE commands
  205.           (combine them) so that the following line will accomplish the task:
  206.           
  207.           DO-ONCE @Friday DO-ONCE @+1 LIONCLUB.BAT
  208.           
  209.           hence, the LIONCLUB.BAT file will get run on or after the first day
  210.           of the month....BUT...it never even gets requested to run unless it's
  211.           Friday, so it will ONLY be run on the first Friday of the month...
  212.           and then not until the next month!
  213.  
  214.           To stack them properly, you should place the less restrictive re-
  215.           quirement FIRST, (the one that happens MORE often) and the more 
  216.           restrictive requirement second.  That is, place the @FRIDAY  
  217.           (which occurs more often) first, and the @+1  (which occurs less 
  218.           often) second.  You can follow the logic through, or just take 
  219.           my word for it.
  220.  
  221. --------------------------------- MORE JUNK --------------------------------
  222.  
  223. For those of you who like to keep your root directory free of all un-necessary
  224. files, you can instruct DO-ONCE to keep its data file in another directory, or
  225. even on another drive.  To do so, just set an environment variable with the 
  226. name of the desired drive\path...by putting a line in your AUTOEXEC.BAT file
  227. like this:
  228.  
  229. SET DO-ONCE=C:\UTIL
  230.  
  231. (with or without the final backslash)
  232.  
  233. Make sure this line occurs in your AUTOEXEC.BAT  *before* any lines which
  234. run DO-ONCE, or DO-ONCE won't know where to find your data file, and it will
  235. use the default (root) directory of the current drive for its data file.
  236.  
  237.                               - - - - - - - - - - -
  238.  
  239. For those of you who also like to keep your screen uncluttered, a QUIET MODE
  240. can be specified by placing the "quiet switch" in the environment variable.
  241. The quiet switch is   /Q   placed AFTER the directory name, like so:
  242.  
  243. SET DO-ONCE=C:\UTIL /Q
  244.  
  245. Make sure there is at least one space separating the directory name and the
  246. quiet switch, as shown above.  You can activate the quiet switch without
  247. specifying a directory with the command:    SET DO-ONCE=/Q
  248.  
  249. You may also specify the /Q switch as the FIRST parameter on the command
  250. line, after the words DO-ONCE.
  251.  
  252. The quiet switch will suppress all extraneous information regarding when
  253. the requested program was last run, etc.  If the DO-ONCE copyright notice 
  254. is already displayed on the screen (which I assume would mean you've just
  255. run it -- unless you just like "ECHO"ing my name to your screen!) the 
  256. quiet switch will suppress repeated displays of it, so you don't have to
  257. stare at 20 copies of my name on your screen.  You will, however see
  258. a   .   displayed each time, just to let you know it's working.
  259.  
  260. If the requested program is going to be run, the command line will be
  261. displayed on the screen, just as if you'd typed it in from DOS.  This is
  262. true whether you're running in quiet mode or not.  If you REALLY like a
  263. clear screen, you can clear even this up by redirecting output to 
  264. the NUL device...like so:
  265.  
  266.                          DO-ONCE Myprog >NUL
  267.     
  268. The copyright notice will not be suppressed by re-direction.
  269.  
  270. Even in quiet mode, any DOS error messages will continue to be displayed, as
  271. will any output from your program, just like normal.
  272.  
  273.                               - - - - - - - - - - -
  274.  
  275. For those command lines which require re-direction, instead of including
  276. the > symbol on the DO-ONCE command line (which DOS will interpret as re-
  277. directing the output of DO-ONCE, not your program)...you can insert the
  278. following two part symbols:
  279.  
  280. `]  will be replaced with the > symbol.
  281. `[  will be replaced with the < symbol.
  282. `^  will be replaced with the | symbol.
  283.  
  284. Please note, this is a backwards apostrophe (ASCII character 96), followed
  285. by a right square bracket, left square bracket, or caret mark.
  286.  
  287. CAUTION: Using a disk-optimizing program while output is being redirected to
  288. a file can cause cross-linkage of file clusters.  This has nothing to do with
  289. DO-ONCE, but is true whenever such programs are run.  This caution is being 
  290. included here just to save you some headaches.  If you are using such a 
  291. program, or any program which *directly* manipulates the File Allocation 
  292. Table (FAT) then do NOT re-direct output to a file.  (You can still redirect 
  293. output to a device such as NUL or PRN without any problems.)
  294.  
  295. Example:   DO-ONCE @SUN DIR `] SUN.DIR        will be executed on Sunday as
  296.            DIR > SUN.DIR
  297.  
  298. If you have no idea what I'm talking about with re-direction and piping,
  299. that's OK.  If you haven't found it necessary to learn these DOS tools yet,
  300. you needn't learn them just for DO-ONCE.
  301.  
  302.  
  303. ----------------------------- HOW DO-ONCE WORKS -----------------------------
  304. ------------------------ (useless technical details) ------------------------
  305.           
  306. What DO-ONCE does is to keep a record of requested programs (a requested 
  307. program is like TIMESET or VOPT, in the above examples).  It keeps a record
  308. of requested programs in a file  DO-ONCE.DAT.  This file is kept in the 
  309. root directory of the currently active drive. (unless a different directory
  310. is SET in the environment)  When I request a program, it first checks to see
  311. if I've requested it to occur only on one particular day, for instance only
  312. on Mondays, or only on the 15th of the month.  If I have, and it isn't
  313. currently Monday, then DO-ONCE checks to see if I've requested the "or after"
  314. function, and if the program was run on the last requested day.  If it WAS
  315. so run, DO-ONCE immediately quits, and my AUTOEXEC.BAT file continues on as
  316. usual.
  317.  
  318. If it is Monday, etc., or if no @DAY request has been made, then it checks the 
  319. DO-ONCE.DAT file to see when that program was last requested.  If the date
  320. it was last requested isn't the same as the current day, month, and year, then
  321. DO-ONCE loads a copy of COMMAND.COM, and passes the FILENAME and any parameters
  322. on to DOS.  This way, you can run a BAT file, COM file, or EXE file using
  323. DO-ONCE.  Note, however, the caution below that you should NEVER request
  324. a resident or TSR program directly from DO-ONCE.  Finally, DO-ONCE updates
  325. the DO-ONCE.DAT file to reflect the fact that it has now run that particular
  326. requested program.  (note, since it runs the requested program from within
  327. a secondary copy of COMMAND.COM, you can tell it to run a BATCH file, and
  328. when that batch file is finished, it will return back to your autoexec batch
  329. file and continue where it left off.)
  330.  
  331. Note that DO-ONCE closes all data files and cleans up its directory entries
  332. before running the requested program, so that programs like disk optimizers
  333. or non-destructive low level formatters can operate without messing up the
  334. DO-ONCE files.
  335.  
  336. The structure of the DO-ONCE.DAT file is as follows:
  337.  
  338.   Year   : Word  (2 bytes)
  339.   Month  : Word  (2 bytes)
  340.   Day    : Word  (2 bytes)
  341.   Len     : Byte  (length of the command line executed)
  342.   C_line : 128 bytes (normal limit for DOS command line)
  343.   
  344. The reason the C_Line field is 128 bytes is that DOS can accept a command line
  345. only that long.
  346.   
  347. If the requested program has not yet been run (that is, if there is no match
  348. for the command line) then the name and date are added to the file, and the
  349. program is run.
  350.  
  351. NOTE:  -- DO-ONCE will ALWAYS run a program the first time it is requested,
  352.           even if it's NOT Monday, or whatever.
  353.  
  354. Note that you need not enter any extension for the FILENAME. (.BAT, .COM,
  355. etc), unless you want to force DOS to run a BAT program instead of an
  356. identically named COM program, etc.
  357.  
  358. Also note that it records the [d:\path\]FILENAME *and* any parameters.  It
  359. will EXECUTE the FILENAME with any parameters you put after it, and also store
  360. it as such, so that the same program can be run with different parameters, as
  361. in the VOPT example above. 
  362.  
  363. The "quiet mode" checks to see if the DO-ONCE copyright notice is found
  364. somewhere on the screen (which usually means you've got several DO-ONCE
  365. requests in a row).  If it finds the notice, it supresses repeated 
  366. displays of the copyright notice; It will also supress any information 
  367. regarding the requested program.  All you will see is a collection of
  368. dots -- one for each time DO-ONCE is run.  That way, you only have to
  369. look at the copyright notice once.  (I use DO-ONCE about 10 times in a row
  370. in my AUTOEXEC.BAT, and I got tired of seeing my own name filling up the
  371. screen all the time...I mean, I like my name as much as anyone, but that's
  372. ridiculous!)
  373.  
  374. Although the data file is actually accessed and read each time you run
  375. DO-ONCE, sometimes it doesn't actually change anything, but just ends up
  376. leaving the file exactly as it was.  You will notice, however,
  377. that the file date and time stamp are updated...so you can tell the last
  378. time you ran DO-ONCE just by looking at the date of your DO-ONCE.DAT file.
  379.  
  380. DO-ONCE was written using Borland's Turbo Pascal, Version 6.0.
  381. It also makes use of Bob Ainsbury's excellent shareware function library,
  382. the "TechnoJock's Turbo Toolkit."  (Yes, I registered it, did you?)
  383.  
  384. The source code for DO-ONCE is not available for distribution because
  385.   1) I don't want everyone making fun of my code (OK, I'll admit it).
  386.   2) I don't want to have to comment every line of the source.
  387.   3) It uses several of my own units for date, string, and environment
  388.      handling which I do not want released.
  389.   4) I don't want J. Random Dufus to modify (and mess up) the program.
  390.      That's why it's copyrighted.
  391.  
  392.                            - - - - - - - - - - -
  393.  
  394. If you have any questions, problems, or suggestions, please let me know.  If I
  395. can make the program more useful for you, also let me know.
  396.  
  397. Thanks to Bob Gellman, Mike Focke, Andy Glass, Paul Shahood, Mark Freeman, and
  398. Paul Thorpe for suggestions and improvements.
  399.  
  400. Glenn Snow
  401. 6401 S. Harper Ave
  402. Chicago, IL  60637
  403. (312) 684-9135 (voice only, please)
  404.  
  405. -------------------------------------------------
  406. Version history
  407.  
  408. 1.0 -- Original DO-ONCE, written in ASM.  Limited release to the public.
  409.        (May, 1987)
  410.        
  411. 1.1 -- Fixed bug which cut command line short when @DAY parameter used with
  412.        entire day name.  (Nov, 1987)  First release as freebie.  (NO donations
  413.        requested.)
  414.        
  415. 1.2 -- Re-written in Turbo Pascal 4.0  -- Accepts a path designation in front
  416.        of the requested program.  Identifies itself with DO-ONCE message when
  417.        run.  (Thanks to Bob Gellman for the suggestion).
  418.        
  419. 1.3 -- Now stores ENTIRE command line, including parameters, like the VOPT
  420.        example above.  (Thanks to Mike Focke for the suggestion).  Also 
  421.        identifies the requested program before it runs it.
  422.        
  423. 1.4 -- Displays requested program on screen while checking to see if it should
  424.        be run.  Added carriage return and line feed before identifying itself.
  425.  
  426. 2.0 -- A dog.  Although several "enhancements" were added, several bugs
  427.        were added as well...Fatal Error #127 (Incredible Programmer Stupidity)
  428.        was the main cause.  If you have this version, get rid of it!
  429.        (Bad dog! Bad dog! Down boy!)
  430.  
  431. 2.1 -- Several enhancements, which now work.  All unintended "features" (bugs)
  432.        were removed.
  433.          a) Added the monthly option
  434.          b) Added the "or after" option
  435.          c) Allowed the data file to exist elsewhere than in the root directory
  436.             by the use of the DO-ONCE environment variable
  437.          d) Gives a more detailed run/no-run message
  438.          e) Returns consistent ERRORLEVEL responses
  439.          (Thanks to Andy Glass and Paul Shahood for the GREAT suggestions,
  440.           and again to Paul Shahood for patience with the Bad Dog version)
  441.    
  442. 2.2 -- Two simple enhancements and a bug fix.
  443.        a) Enhancement: Quiet mode is added.
  444.           Thanks to Paul Thorpe for the suggestion.
  445.        b) Supports redirection and piping.
  446.           Thanks to *me* for the suggestion.
  447.        b) Bug fix: If the DO-ONCE.DAT file does not need to be changed 
  448.           (i.e. the requested program was not run) then its archive bit is
  449.           left as it was.  This means that it will not be incorrectly marked
  450.           as needing backup.  Thanks to Mark Freeman for the suggestion.
  451.           
  452. 2.3 -- Added ability to set quiet mode from command line by setting the
  453.          first parameter as   /Q
  454.        (now using Turbo Pascal 6.0)  
  455.  
  456.        
  457. --------------------------- END OF DOCUMENTATION ------------------------
  458.